﻿<UserControl x:Class="Autobiography.UI.History"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:design="clr-namespace:Autobiography.Design"
             xmlns:model="clr-namespace:Autobiography.Model"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="800" DataContext="{Binding}">
    <UserControl.Resources>
        
        <design:DateGrouping x:Key="dateGroupingDS" />

        <Style x:Key="FlatControl">
            <Setter Property="Control.Background" Value="{x:Null}" />
            <Setter Property="Control.BorderBrush" Value="{x:Null}" />
            <Style.Triggers>
                <Trigger Property="Control.IsMouseOver" Value="True">
                    <Setter Property="Control.Background" Value="{x:Null}" />
                    <Setter Property="Control.BorderBrush" Value="{x:Null}" />
                    <Setter Property="Control.FontWeight" Value="Bold" />
                </Trigger>
                <Trigger Property="Control.IsFocused" Value="True">
                    <Setter Property="Control.FontWeight" Value="Bold" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style x:Key="FlatButton" BasedOn="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" TargetType="Button">
            <Style.Triggers>
                <Trigger Property="Control.IsMouseOver" Value="True">
                    <Setter Property="Control.FontWeight" Value="Bold" />
                </Trigger>
                <Trigger Property="Control.IsFocused" Value="True">
                    <Setter Property="Control.FontWeight" Value="Bold" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <DataTemplate x:Key="FileEntryHistory">
            <Border Name="Border" BorderBrush="Silver" BorderThickness="1" Padding="2" Margin="2">
                <StackPanel x:Name="MyStack" Width="175">
                    <Expander ExpandDirection="Down" IsExpanded="True">
                        <Expander.Header>
                            <StackPanel>
                                <TextBlock Text="{Binding Path=Key}" FontWeight="Bold" />
                            </StackPanel>
                        </Expander.Header>
                        <ListBox x:Name="SubListBox" ItemsSource="{Binding}" SelectionChanged="SubListBox_SelectionChanged">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Width="150">
                                        <TextBlock Text="{Binding Path=Modified}" MouseDown="TextBlock_MouseDown" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Expander>
                </StackPanel>
            </Border>
        </DataTemplate>

    </UserControl.Resources>
    
    <Grid x:Name="grid">
        <DockPanel x:Name="dock"
                    Height="{Binding ElementName=grid, Path=ActualHeight}"
                    Width="{Binding ElementName=grid, Path=ActualWidth}"
                    >
            <DockPanel x:Name="buttons" DockPanel.Dock="Bottom" >
                <Button x:Name="okButton" Style="{StaticResource FlatButton}" Click="okButton_Click" Width="150" DockPanel.Dock="Right">Restore Selected Version</Button>
                <Button x:Name="cancelButton" Style="{StaticResource FlatButton}" Click="cancelButton_Click" Width="50" DockPanel.Dock="Right">Cancel</Button>
                <TextBlock></TextBlock>
            </DockPanel>
            
            <ListBox Name="TopLevelListBox"
                     ItemsSource="{StaticResource dateGroupingDS}"
                     ItemTemplate="{StaticResource FileEntryHistory}" SizeChanged="TopLevelListBox_SizeChanged" />
        </DockPanel>
    </Grid>    
</UserControl>
